package cl.zeke.remoto.jaxws;

import cl.zeke.comun.dto.Persona;
import cl.zeke.remoto.negocio.services.ComunesService;
import javax.jws.WebMethod;
import javax.jws.WebService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;

/**
 *
 * @author taller
 */
@WebService(name = "PersonaSoapService")
public class PersonaSoapService extends SpringBeanAutowiringSupport {

    private static Logger log = LoggerFactory.getLogger(PersonaSoapService.class);

    @Autowired
    private ComunesService comunesService;

    @WebMethod
    public Persona traerPorNombre(String nombre) {
        SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
        return comunesService.traerPersona(nombre);
    }

    @WebMethod
    public Boolean guardarPersona(Persona p) {
        try {
            log.info("guardando");
            log.info("p: " + p.getNombre() + " " + p.getEdad());
            for (Persona f : p.getFamiliares()) {
                log.info("f: " + f.getNombre() + " " + f.getEdad());
            }
            return true;
        } catch (Exception ex) {
            return false;
        }
    }

}
